package com.dmscpt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * 常用字段默认值自动填充
 */
@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date currentDate = new Date();
        //默认未删除
        setFieldValByName("deleted", "0",metaObject);
        //创建时间默认当前时间
        setFieldValByName("createTime", currentDate,metaObject);
        //修改时间
        setFieldValByName("updateTime",currentDate,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Date currentDate = new Date();
        //修改时间
        setFieldValByName("updateTime",currentDate,metaObject);
    }
}
